package logic

import (
	"context"
	"goods/goodsrpc/goodsrpcclient"

	"goods/api/internal/svc"
	"goods/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ClassAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewClassAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClassAddLogic {
	return &ClassAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ClassAddLogic) ClassAdd(req *types.ClassAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	class, err := l.svcCtx.GoodsRpc.ClassAdd(l.ctx, &goodsrpcclient.ClassAddRequest{
		Name:    req.Name,
		UserId:  req.UserId,
		GoodNum: req.GoodsNum,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}
	return &types.Response{
		Message: "分类添加成功",
		Data:    class,
		Code:    200,
	}, nil
}
